package com.example.demo.service.Impl;

import com.example.demo.bean.BaseConfig;
import com.example.demo.bean.BaseConfigExample;
import com.example.demo.dao.BaseConfigMapper;
import com.example.demo.service.IBaseConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
@Service
public class BaseConfigServiceImpl implements IBaseConfigService {
    @Autowired
    private BaseConfigMapper baseConfigMapper;
    @Override
    public List<BaseConfig> query(Long id) {
        BaseConfigExample example=new BaseConfigExample();
        if (!StringUtils.isEmpty(id)) {
            example.createCriteria().andIdEqualTo(id);
        }
        List<BaseConfig> list=baseConfigMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(BaseConfig baseConfig) {
        if(baseConfig.getId()==null){
            baseConfigMapper.insert(baseConfig);
        }else{
            baseConfigMapper.updateByPrimaryKey(baseConfig);
        }
    }

    @Override
    public void deleteById(long id) {
        baseConfigMapper.deleteByPrimaryKey(id);
    }
}
